<template>
  <div class="login">
    <div class="title">嗨购后台管理系统</div>
    <el-form :model="form" class="loginform" ref="ruleFormRef" :rules="rules">
      <el-form-item prop='adminname'>
        <el-input v-model="form.adminname" placeholder="默认账号:admin"/>
      </el-form-item>
       <el-form-item prop='password'>
        <el-input v-model="form.password" show-password placeholder="默认密码:123456"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref,reactive } from "vue";

import { ElNotification } from 'element-plus'
import 'element-plus/es/components/notification/style/css'

import { useRouter } from 'vue-router'
import {login} from '@/api/index'
import { useLoginStore } from '@/stores/login'

var form=ref({adminname:'',password:''})

var $router=useRouter()
var loginStore=useLoginStore()

var onSubmit=async()=>{
    var ok=await login(form.value)
    console.log(ok);
    if(ok.data.code==200){
         ElNotification({
          title:'登录通知',
          message:ok.data.message,
          type:'success',
          duration: 1500
        })
        loginStore.saveLoginData(ok.data.data)
        $router.push('/index')
    }else{
         ElNotification({
          title:'登录通知',
          message:ok.data.message,
          type:'error',
          duration: 1500
        })
    }
}
</script>

<style scoped lang='scss'>
.login {
  height: 100%;
  background: url(../../assets/bg.jpg);
  display: flex;
  background-repeat: no-repeat;
  background-size: cover;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .title{
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 600;
  }
  .loginform{
    background-color: white;
    padding: 30px;
    border-radius: 5%;
    width: 300px;
  }
  .el-button {
        width: 100%;
  }
}
</style>